//package top.yangbuyi.controller.system;
//
//import com.ruoyi.common.constant.Constants;
//import com.ruoyi.common.utils.StringUtils;
//import com.ruoyi.framework.aspectj.lang.annotation.Log;
//import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
//import com.ruoyi.framework.redis.RedisCache;
//import com.ruoyi.framework.security.LoginUser;
//import com.ruoyi.framework.web.controller.BaseController;
//import com.ruoyi.framework.web.domain.AjaxResult;
//import com.ruoyi.framework.web.page.TableDataInfo;
//import com.ruoyi.project.monitor.domain.SysUserOnline;
//import com.ruoyi.project.system.service.ISysUserOnlineService;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.ValueOperations;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.web.bind.annotation.*;
//import top.yangbuyi.acpect.annotaction.Log;
//import top.yangbuyi.acpect.enums.BusinessType;
//import top.yangbuyi.constants.Constants;
//import top.yangbuyi.domain.OperLog;
//import top.yangbuyi.domain.SysUserOnline;
//import top.yangbuyi.domain.User;
//import top.yangbuyi.vo.AjaxResult;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.Collections;
//import java.util.List;
//
///**
// * 在线用户监控
// *
// * @author ruoyi
// */
//@RestController
//@RequestMapping("/monitor/online")
//public class SysUserOnlineController extends BaseController
//{
//    @Autowired
//    private ISysUserOnlineService userOnlineService;
//
//    @Autowired
//    private RedisTemplate redisCache;
//
//    @GetMapping("/list")
//    public AjaxResult list(String ipaddr, String userName)
//    {
//        Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN + "*");
//        List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
//        for (String key : keys)
//        {
//            ValueOperations<String, OperLog> operation = redisCache.opsForValue();
//            OperLog user = operation.get(key);
//
//            if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
//            {
//                if (StringUtils.equals(ipaddr, user.getOperIp()) && StringUtils.equals(userName, user.getOperName()))
//                {
//                    userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
//                }
//            }
//            else if (StringUtils.isNotEmpty(ipaddr))
//            {
//                if (StringUtils.equals(ipaddr, user.getIpaddr()))
//                {
//                    userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
//                }
//            }
//            else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser()))
//            {
//                if (StringUtils.equals(userName, user.getUsername()))
//                {
//                    userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
//                }
//            }
//            else
//            {
//                userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
//            }
//        }
//        Collections.reverse(userOnlineList);
//        userOnlineList.removeAll(Collections.singleton(null));
//        return AjaxResult.success(userOnlineList);
//    }
//
//    /**
//     * 强退用户
//     */
//    @Log(title = "在线用户", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{tokenId}")
//    public AjaxResult forceLogout(@PathVariable String tokenId)
//    {
//        redisCache.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId);
//        return AjaxResult.success();
//    }
//}
